home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / devices / src / opendevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.6 KB  |  113 lines

  1. /*
  2.     (C) 1995, 96 AROS - The Amiga Replacement OS
  3.     (C) 1995 AROS - The Amiga Replacement OS
  4.     $Id$
  5.     $Log$
  6.     Desc:
  7.     Lang: english
  8. */
  9. #include "exec_intern.h"
  10. #include <exec/devices.h>
  11. #include <exec/io.h>
  12. #include <exec/errors.h>
  13. #include <aros/libcall.h>
  14.  
  15. /*****************************************************************************
  16.  
  17.     NAME */
  18.     #include <exec/libraries.h>
  19.     #include <clib/exec_protos.h>
  20.  
  21.     __AROS_LH4(BYTE, OpenDevice,
  22.  
  23. /*  SYNOPSIS */
  24.     __AROS_LA(STRPTR,             devName,    A0),
  25.     __AROS_LA(ULONG,              unitNumber, D0),
  26.     __AROS_LA(struct IORequest *, iORequest,  A1),
  27.     __AROS_LA(ULONG,              flags,      D1),
  28.  
  29. /*  LOCATION */
  30.     struct ExecBase *, SysBase, 74, Exec)
  31.  
  32. /*  FUNCTION
  33.     Tries to open a device and fill the iORequest structure.
  34.     And error is returned if this fails, 0 if all went well.
  35.  
  36.     INPUTS
  37.     devName    - Pointer to the devices's name.
  38.     unitNumber - The unit number. Most often 0.
  39.     iORequest  - Pointer do device specific information.
  40.              Will be filled out by the device.
  41.              Must lie in public (or at least shared) memory.
  42.     flags       - Some flags to give to the device.
  43.  
  44.     RESULT
  45.     Error code or 0 if all went well. The same value can be found
  46.     in the io_Error field.
  47.  
  48.     NOTES
  49.  
  50.     EXAMPLE
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.     CloseDevice()
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.  
  61. *****************************************************************************/
  62. {
  63.     __AROS_FUNC_INIT
  64.  
  65.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  66.     struct Device *device;
  67.     BYTE ret=IOERR_OPENFAIL;
  68.  
  69.     /* Arbitrate for the device list */
  70.     Forbid();
  71.  
  72.     /* Look for the device in our list */
  73.     device=(struct Device *)FindName(&SysBase->DeviceList,devName);
  74.  
  75.     /* Something found ? */
  76.     if(device!=NULL)
  77.     {
  78.     /* Init iorequest */
  79.     iORequest->io_Error=0;
  80.     iORequest->io_Device=device;
  81.     iORequest->io_Flags=flags;
  82.     iORequest->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  83.  
  84.     /* Call Open vector. */
  85.     __AROS_LC3 (LONG, openDevice,
  86.         __AROS_LCA(struct IORequest *, iORequest,  A1),
  87.         __AROS_LCA(ULONG,              unitNumber, D0),
  88.         __AROS_LCA(ULONG,              flags,      D1),
  89.         struct Device *, device, 1, Device);
  90.  
  91.     /* Check for error */
  92.     ret=iORequest->io_Error;
  93.     if(ret)
  94.         /* Mark request as non-open */
  95.         iORequest->io_Device=NULL;
  96.     }
  97.     /*
  98.     else
  99.     {
  100.     Under normal circumstances you'd expect the device loading here -
  101.     but this is only exec which doesn't know anything about the
  102.     filesystem level. Therefore dos.library has to SetFunction() this vector
  103.     for the additional functionality.
  104.     }
  105.     */
  106.  
  107.     /* All done. */
  108.     Permit();
  109.     return ret;
  110.     __AROS_FUNC_EXIT
  111. } /* OpenDevice */
  112.  
  113.